import { join } from "path";
import { app } from "electron";

const env = app.isPackaged ? "production" : "development";

const filePath = {
  winURL: {
    development: `http://localhost:${process.env.PORT}`,
    production: `file://${join(
      app.getAppPath(),
      "dist",
      "electron",
      "renderer",
      "index.html"
    )}`,
  },

  loadingURL: {
    development: `http://localhost:${process.env.PORT}/loader.html`,
    production: `file://${join(
      app.getAppPath(),
      "dist",
      "electron",
      "renderer",
      "loader.html"
    )}`,
  },
  getPreloadFile(fileName: string) {
    if (env !== "development") {
      return join(
        app.getAppPath(),
        "dist",
        "electron",
        "main",
        `${fileName}.js`
      );
    }
    return join(app.getAppPath(), `${fileName}.js`);
  },
};

export const winURL = filePath.winURL[env];
export const loadingURL = filePath.loadingURL[env];
export const getPreloadFile = filePath.getPreloadFile;
